/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.vienthonga.homepage.logic;

import com.vienthonga.hibernate.dao.ShowProductDAO;
import com.vienthonga.hibernate.pojo.TProduct;
import java.util.List;

/**
 *
 * @author DoanHa
 */
public class ShowMobilephoneLogic {

    public List<TProduct> getNewMobilephone(int pageIndex) {

        int itemsOnPage = GetItemsOnPage();
        int start = (pageIndex - 1) * itemsOnPage;
        return ShowProductDAO.getNewMobilephone(start, itemsOnPage);
    }

    public List<TProduct> getNormalMobilephone(int pageIndex) {

        int itemsOnPage = GetItemsOnPage();
        int start = (pageIndex - 1) * itemsOnPage;
        return ShowProductDAO.getNormalMobilephone(start, itemsOnPage);
    }

    public List<TProduct> getMediumMobilephone(int pageIndex) {

        int itemsOnPage = GetItemsOnPage();
        int start = (pageIndex - 1) * itemsOnPage;
        return ShowProductDAO.getMediumMobilephone(start, itemsOnPage);
    }

    public List<TProduct> getHighMobilephone(int pageIndex) {

        int itemsOnPage = GetItemsOnPage();
        int start = (pageIndex - 1) * itemsOnPage;
        return ShowProductDAO.getHighMobilephone(start, itemsOnPage);
    }

    public List<TProduct> getSuperMobilephone(int pageIndex) {

        int itemsOnPage = GetItemsOnPage();
        int start = (pageIndex - 1) * itemsOnPage;
        return ShowProductDAO.getSuperMobilephone(start, itemsOnPage);
    }

    public int GetItemsOnPage() {
        return ShowProductDAO.GetItemsOnPage();
    }

    public int caculatePaging(String action) {
        //tinh so trang dua vao action
        int numberOfPage;
        int totalItem = 0;

        if (action.equals("new")) {
            totalItem = ShowProductDAO.GetNewMobilephoneTotal();
        } else if (action.equals("normalMobilephone")) {
            totalItem = ShowProductDAO.getNormalMobilephoneTotal();
        } else if (action.equals("mediumMobilephone")) {
            totalItem = ShowProductDAO.getMediumMobilephoneTotal();
        } else if (action.equals("highMobilephone")) {
            totalItem = ShowProductDAO.getHighMobilephoneTotal();
        } else {
            totalItem = ShowProductDAO.getSuperMobilephoneTotal();
        }

        int itemOnPage = GetItemsOnPage();
        if (totalItem % itemOnPage == 0) {
            numberOfPage = totalItem / itemOnPage;
        } else {
            numberOfPage = totalItem / itemOnPage + 1;
        }
        return numberOfPage;
    }
}
